/*
 * ===================================================
 *
 *       Filename:  main.c
 *
 *
 *        Created:  10/18/2011 06:49:05 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  durand_y, <durand.yoan@gmail.com>
 *
 * ===================================================
 */
#include "parser.h"
#include <stdio.h>


int             main(int    argc,
                     char   **argv)
{
  char          *trace = NULL;
  char          **map = NULL;
  s_car         *car = NULL;
  int           p_err = 0;
  int           m_err = 0;

  trace = malloc(sizeof (char) * MAX_BUFF_SIZE);
  read(STDIN_FILENO, trace, MAX_BUFF_SIZE);
  car = init();
  if (argc == 0)
    write(STDOUT_FILENO, "error\n", 6);
  if (((p_err = parse_trace(trace)) == 0) && ((m_err = parse_track(argv[1])) == 0))
  {
    map = create_map(argv[1]);
    start_pos(&car, map);
    if ((run_trace(trace, car, map)) == NULL)
      return (2);
    else
      return (0);
  }
  else
  {
    if (p_err != 0)
      return (m_err);
    else
      return (p_err);
  }
}
